#! /bin/sh

KERNEL_VERSION=$(readlink /boot/zImage | perl -pe 's/zImage-//')
MODULES_DIR=/lib/modules/${KERNEL_VERSION}

for mod in $(ls ${MODULES_DIR}/extra/*ko 2> /dev/null) ; do 
  find ${MODULES_DIR}/kernel -name $(basename $mod) -exec rm -f {} \;
done

depmod -a ${KERNEL_VERSION}

# make sure we're OK even before rebooting to the new kernel
ln -sf $MODULES_DIR /lib/modules/$(uname -r)

if [ -e /dev/mtdblock2 ] ; then
  dd if=/boot/vmlinux-${KERNEL_VERSION}.trx of=/dev/mtdblock2 bs=1M 2> /dev/null
fi
